home *** CD-ROM | disk | FTP | other *** search
- Path: microl4.microlise.UUCP!news
- From: andrewg@microlise.co.uk (Andrew Gierth)
- Newsgroups: comp.lang.c++
- Subject: Re: copy ctor and derived classes
- Date: 13 Jan 1996 07:22:52 GMT
- Organization: Microlise Engineering Ltd.
- Message-ID: <4d7mkc$fkm@microl4.microlise.UUCP>
- References: <DL38zz.50K@Virginia.EDU> <4d6u37$3b7@news.bridge.net>
- Reply-To: andrewg@microlise.co.uk (Andrew Gierth)
- NNTP-Posting-Host: andrewg.microlise.uucp
- X-NNTP-Posting-Host: microl.demon.co.uk
- X-Newsreader: IBM NewsReader/2 v1.2.5
-
- In <4d6u37$3b7@news.bridge.net>, David Byrden <100101.2547@compuserve.com> writes:
- >
- >Greg;
- >
- >>> how can I invoke the base class's copy constructor in the
- >>> intialization list the derived class doesn't have to deal
- >>> with all of the little bits of the base class?
- >
- >The derived class has no RIGHT to deal with all the bits of the
- >base class. They can be private.
- >
- >Here's what to do:
- >
- >Derived::Derived( const Derived& rhs ) // copy ctor
- > : Base( *this ) // invoke base's copy ctor
- >{
- >
- >}
- >
- >The copy ctor which the compiler can silently fgenerate for you,will do
- >this a utomatically.
-
- You're trying to copy the object to itself!
-
- Don't you mean:
-
- Derived::Derived(const Derived& rhs)
- : Base(rhs)
- {
- }
-
- -- Andrew (andrewg@microlise.co.uk)
-
- [.sig under construction]
-
-